<template>
    <div id="app">

        <!-- <x-header >
           <span >盘点单 任务中</span>
           <x-icon slot="overwrite-left" type="ios-arrow-thin-left" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
         </x-header>-->
       <!-- <x-header :left-options="{showBack: false}" @on-click-title="cs"></x-header>-->

        <x-header @on-click-title="cs"  :left-options="{showBack: false}"   >盘点单 任务中</x-header>

        <x-table :cell-bordered="false" style="background-color:#fff;">
            <thead>
            </thead>
            <tbody>
            <tr>
              <td style="width: 50%"><div style="width: 95%;
    margin-left: 5%;"><span style="color: #bbc1cd;" >工号:</span><span style="color: #343f51">{{gh}}</span></div></td>
              <td style="width: 50%"><div style="width: 95%;
                                          margin-right: 5%; text-align: right"><router-link  :to="{ path:'/scan/id', query: { gh:  gh} }"><span style="color: #bbc1cd;" >卡片数:</span><span style="color:#4192f5">{{size}}</span></router-link></div></td>

            </tr>

            </tbody>
        </x-table>
        <tabbar>
            <tabbar-item>

                <span slot="label"> <x-button type="primary" class="sm-btn"  @click.native="Scan">扫码盘点</x-button></span>
            </tabbar-item>


        </tabbar>


        <div class="fhome-wrapper">
            <a href="/wd-wechart/homePage/homePage.html">
                <i class="fixed-home"></i>
            </a>

        </div>

        <div v-transfer-dom>
            <loading :show="modelshow==1" :text="加载中"></loading>
        </div>


    </div>
</template>

<script>
    import { XHeader, Actionsheet, TransferDom, ButtonTab, ButtonTabItem } from 'vux'
    import { XInput, Group, XButton, Cell } from 'vux'
    import { XTable, LoadMore } from 'vux'
    import { AjaxPlugin } from 'vux'
    import {Tabbar, TabbarItem} from 'vux'
    import { Loading } from 'vux'

    export default {
        directives: {
            TransferDom
        },
        components: {
            XHeader,
            Actionsheet,
            ButtonTab,
            ButtonTabItem,
            XInput,
            XButton,
            Group,
            Cell,
            XTable,
            LoadMore,
            AjaxPlugin,
            Tabbar,
            TabbarItem,
            Loading
        },
        data () {
            return {
                gh: '',
                size: '',
                enterText: '',
                valid1: false,
                valid2: false,
                iconType: '',

                style: '',
                disabledValue: 'hello',
                debounceValue: '',
                maxValue: '',
                maskValue: '13545678910',
                maskValue2: '',
                menus: {
                    menu1: 'Take Photo',
                    menu2: 'Choose from photos'
                },
                showMenus: false,
                returndata:'',
                code:'',
                onepageurl:'',
                modelshow:'0'
            }
        },
        mounted(){

   this.InitPagedata();
        },

        methods: {
            GetQueryString(name)
            {
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            },

            InitPagedata () {
                this.$http.post(this.onepageurl+'/wd-wechart/Inventory/QueryIntPage')
                        .then((data) => {


                      this.gh=data.data.gh;
                      this.size=data.data.size;

                        }).catch(e => {
                    // 打印一下错误
                    console.log(e)
                })
            },

            Scan(){
var   thisvue=this;
                if(thisvue.modelshow=='1'){
                    return;

                }
                thisvue.modelshow='1'
                var url=window.location.href.split('#')[0]
                AjaxPlugin.$http.post(thisvue.onepageurl+'/wd-wechart/Validate/wxtest?url='+encodeURIComponent(url))
                        .then((data) => {
                            thisvue.modelshow='0'
                            this.password2=data
                            var  wx=this.$wechat;
                            wx.config({
                                beta: true,
                                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                                appId: this.password2.data.map.appId, // 必填，公众号的唯一标识
                                timestamp: this.password2.data.map.timestamp, // 必填，生成签名的时间戳
                                nonceStr: this.password2.data.map.nonceStr, // 必填，生成签名的随机串
                                signature: this.password2.data.map.signature,// 必填，签名，见附录1
                                jsApiList: [
                                    'scanQRCode'
                                ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                            });

                            wx.ready(function(){
                                wx.scanQRCode({
                                    desc: 'scanQRCode desc',
                                    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                                    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                                    success: function (res) {
                                       var str= res.resultStr.replace(/(^\s*)|(\s*$)/g, "");
                                        qrc(str)
                                    },
                                    error: function(res) {
                                        if (res.errMsg.indexOf('function_not_exist') > 0) {
                                            alert('版本过低请升级')
                                        }
                                    }
                                });



                            });

                            function qrc(params) {

                              /*  thisvue.$router.replace({path:'second/params'});*/
                                thisvue.$router.replace({path:'/second/id',query:{kpbh:params,gh:thisvue.gh,size:thisvue.size}});
                               /* this.cs(params)*/

                               // location.href="http://qizhenjiang163.6655.la/wd-wechart/Validate/test?params="+params
                            }



                        }).catch(e => {
                    // 打印一下错误
                    console.log(e)
                })




            },
            cs(){

                this.$router.replace({path:'/second/id',query:{gh:this.gh,kpbh:'01421152',size:this.size}});
          /*    this.$router.replace({path:'scan/123'});*/

            }





        }



    }
</script>

<style lang="less">
    @import '~vux/src/styles/reset.less';

    #app .overwrite-title-demo {
        margin-top: 5px;
    }
    #app .vux-x-icon {
        fill: #F70968;
    }
    #app .cell-x-icon {
        display: block;
        fill: green;
    }
    #app .buttonstyle{
        margin-top: 38%;

    }
    #app .sm-btn{
      background-color: #4786ff !important;
  }

    body{
        height: 500px;
    }
    .fhome-wrapper{
        position: fixed;
        top:50%;
        right: 0;
        width: 32px;
        height: 32px;
    }
    .fhome-wrapper a{
        display: block;
        width: 100%;
        height: 100%;
    }
    .fixed-home{
        display: block;
        width: 100%;
        height: 100%;
        background: url("./assets/home.png") no-repeat;
        background-position: center;
    }

</style>
